package handler

import (
	"api-getaway/api/register"
	"api-getaway/basic/config"
	"api-getaway/basic/model"
	"github.com/gin-gonic/gin"
	"net/http"
)

func VideoAdd(r *gin.Context) {
	var req register.Video
	err := r.ShouldBind(&req)
	if err != nil {
		r.JSON(http.StatusBadRequest, gin.H{
			"code":    400,
			"message": "参数错误",
		})
		return
	}

	video := model.Video{
		Title: req.Title,
		Cover: req.Cover,
		Type:  req.Type,
	}

	config.DB.Create(&video)
	r.JSON(http.StatusOK, gin.H{
		"code":    200,
		"message": "视频添加成功",
		"data":    video,
	})

}
